import java.util.LinkedList;

public class Expression extends LinkedList<NumSign> {

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (NumSign numSign : this) {
            sb.append(numSign.getStrNumber());
            sb.append(numSign.getSign());
        }
        return sb.toString();
    }

    public String getResult()
    {
        calMulandDiv();
        calAddandSub();
        return this.get(0).getStrNumber();
    }

    private void calMulandDiv()
    {
        for(int i=0;i<this.size();i++)
        {
            if(this.size()==1) return;
            if(this.get(i).getSign()=='*')
            {
                double temp=this.get(i).getNum()*this.get(i+1).getNum();
                this.get(i+1).setNum(temp);
                this.remove(i);
                i=-1;
                continue;
            }
            if(this.get(i).getSign()=='/')
            {
                double temp=this.get(i).getNum()/this.get(i+1).getNum();
                this.get(i+1).setNum(temp);
                this.remove(i);
                i=-1;
                continue;
            }
        }
    }

    private void calAddandSub()
    {
        for(int i=0;i<this.size();i++)
        {
            if(this.size()==1) return;
            if(this.get(i).getSign()=='+')
            {
                double temp=this.get(i).getNum()+this.get(i+1).getNum();
                this.get(i+1).setNum(temp);
                this.remove(i);
                i=-1;
                continue;
            }
            if(this.get(i).getSign()=='-')
            {
                double temp=this.get(i).getNum()-this.get(i+1).getNum();
                this.get(i+1).setNum(temp);
                this.remove(i);
                i=-1;
                continue;
            }
        }
    }

}
